package com.epalmpay.controller.channel.bonus;

import com.epalmpay.commom.BaseController;
import com.epalmpay.exception.ApplicationException;
import com.epalmpay.status.Rescode;
import com.epalmpay.dto.bonus.*;
import com.epalmpay.dto.system.PageDTO;
import com.epalmpay.entity.Page;
import com.epalmpay.enumdef.ActivityEnum;
import com.epalmpay.service.bonus.IBonusSendLogService;
import com.epalmpay.util.Tools;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by gwn on 2017/9/19.
 */
@Controller
@RequestMapping(value="merchant/bonuswarning")
public class BonusWarningController extends BaseController{

    @Resource
    private IBonusSendLogService bonusSendLogService;

    @ResponseBody
    @RequestMapping(value = "/list")
    public BonusWarningListOutDTO bonusSendShopDetail(BonusWarningInDTO bonusWarningInDTO, PageDTO pageDTO)throws Exception{
        BonusWarningListOutDTO bonusWarningListOutDTO = new BonusWarningListOutDTO();
        try {
            Page page= Tools.pageEmtity(pageDTO);
            bonusWarningListOutDTO= bonusSendLogService.queryBonusSendShopList(bonusWarningInDTO,page);

            bonusWarningListOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");

            bonusWarningListOutDTO.setPage(page);
            return bonusWarningListOutDTO;
        } catch (ApplicationException ae) {
            bonusWarningListOutDTO.setErrorCode(ae.errCode, ae.errMsg);
            ae.printStackTrace();
        }
        catch (Exception e) {
            bonusWarningListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
            e.printStackTrace();
        }
        return bonusWarningListOutDTO;

    }


    /**
     *
     * @param bonusWarningInDTO
     * @return
     */
    @RequestMapping(value="/editSuccessStatus")
    @ResponseBody
    public BonusWarningOutDTO editSuccessStatus(BonusWarningInDTO bonusWarningInDTO){
        BonusWarningOutDTO bonusWarningOutDTO=new BonusWarningOutDTO();
        try {

            bonusSendLogService.updateAdjustStatus(bonusWarningInDTO);

            bonusWarningOutDTO.setErrorCode(Rescode.SUCCESS, "修改成功");

            return bonusWarningOutDTO;
        } catch (ApplicationException ae) {
            bonusWarningOutDTO.setErrorCode(ae.errCode, ae.errMsg);
            ae.printStackTrace();
        }
        catch (Exception e) {
            bonusWarningOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
            e.printStackTrace();
        }
        return bonusWarningOutDTO;
    }
    /**
     *
     * @param bonusWarningInDTO
     * @return
     */
    @RequestMapping(value="/editFailStatus")
    @ResponseBody
    public BonusWarningOutDTO editFailStatus(BonusWarningInDTO bonusWarningInDTO){
        BonusWarningOutDTO bonusWarningOutDTO=new BonusWarningOutDTO();
        try {

            bonusSendLogService.updateAdjustStatusFail(bonusWarningInDTO);

            bonusWarningOutDTO.setErrorCode(Rescode.SUCCESS, "修改成功");

            return bonusWarningOutDTO;
        } catch (ApplicationException ae) {
            bonusWarningOutDTO.setErrorCode(ae.errCode, ae.errMsg);
            ae.printStackTrace();
        }
        catch (Exception e) {
            bonusWarningOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
            e.printStackTrace();
        }
        return bonusWarningOutDTO;
    }

    /**
     *
     * @param bonusWarningInDTO
     * @return
     */
    @RequestMapping(value="/bonusSendLogDetail")
    @ResponseBody
    public BonusWarningOutDTO bonusSendLogDetail(BonusWarningInDTO bonusWarningInDTO){
        BonusWarningOutDTO bonusWarningOutDTO=new BonusWarningOutDTO();
        try {

            bonusWarningOutDTO= bonusSendLogService.querybonusSendLogDetail(bonusWarningInDTO);

            bonusWarningOutDTO.setErrorCode(Rescode.SUCCESS, "修改成功");

            return bonusWarningOutDTO;
        } catch (ApplicationException ae) {
            bonusWarningOutDTO.setErrorCode(ae.errCode, ae.errMsg);
            ae.printStackTrace();
        }
        catch (Exception e) {
            bonusWarningOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
            e.printStackTrace();
        }
        return bonusWarningOutDTO;
    }


    //批量更新
    @RequestMapping(value = "/updateAdjustStatus")
    @ResponseBody
    public List<Integer> updateAdjustStatus(@RequestBody List<BonusWarningInDTO> bonusWarningInDTOList) {
            return bonusSendLogService.updateAdjustStatus(bonusWarningInDTOList);

    }


    /**
     *
     * @param bonusWarningInDTO
     * @return
     */
    @RequestMapping(value="/queryBonusData")
    @ResponseBody
    public BonusWarningOutDTO queryBonusData(BonusWarningInDTO bonusWarningInDTO){
        BonusWarningOutDTO bonusWarningOutDTO=new BonusWarningOutDTO();
        try {
            bonusWarningInDTO.setAdjustStatus(ActivityEnum.BonusSendStatus.Freezing.getType());
            bonusWarningOutDTO= bonusSendLogService.queryBonusData(bonusWarningInDTO);
            bonusWarningInDTO.setMemberId(bonusWarningOutDTO.getMemberId());
            int totalCount = bonusSendLogService.queryBonusCount(bonusWarningInDTO);
            bonusWarningOutDTO.setTotalCount(totalCount);
            bonusWarningOutDTO.setErrorCode(Rescode.SUCCESS, "修改成功");

            return bonusWarningOutDTO;
        } catch (ApplicationException ae) {
            bonusWarningOutDTO.setErrorCode(ae.errCode, ae.errMsg);
            ae.printStackTrace();
        }
        catch (Exception e) {
            bonusWarningOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
            e.printStackTrace();
        }
        return bonusWarningOutDTO;
    }


    /**
     *
     * @param bonusWarningInDTO
     * @return
     */
    @RequestMapping(value="/editSuccessStatusAll")
    @ResponseBody
    public BonusWarningOutDTO editSuccessStatusAll(BonusWarningInDTO bonusWarningInDTO){
        BonusWarningOutDTO bonusWarningOutDTO=new BonusWarningOutDTO();
        try {

            bonusSendLogService.updateAdjustStatusAll(bonusWarningInDTO);

            bonusWarningOutDTO.setErrorCode(Rescode.SUCCESS, "修改成功");

            return bonusWarningOutDTO;
        } catch (ApplicationException ae) {
            bonusWarningOutDTO.setErrorCode(ae.errCode, ae.errMsg);
            ae.printStackTrace();
        }
        catch (Exception e) {
            bonusWarningOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
            e.printStackTrace();
        }
        return bonusWarningOutDTO;
    }


}
